import Vue from 'vue';
import App from './App.vue';
import router from './router';
import store from './store';
// 引入element-ui
import Element from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/css/element-variables.scss';
import './assets/css/common.scss';
// 引入echarts
import echarts from 'echarts';
// 引入静态配置数据
import config from './config/staticData';
// 引入共用common静态配置数据
import common from './config/common';
// 引入阿里图标库
import './assets/fonts/iconfont.css';
// 全局引入自定义组件
import backButton from './components/button/goBack';
import comDialog from './components/dialog/index.vue';
import pagination from './components/pagination/index.vue';
import searchner from './components/searchner/index.vue';
Vue.component('back-button', backButton);
Vue.component('comDialog', comDialog);
Vue.component('pagination', pagination);
Vue.component('searchner', searchner);
Vue.config.productionTip = false;
Vue.prototype.$echarts = echarts;
Vue.prototype.$config = config;
Vue.prototype.baseURL = process.env.VUE_APP_BASE_API;
// Vue.prototype.devbaseURL = 'http://192.168.1.11:8082/#/login';
Vue.prototype.analysisURL = process.env.VUE_APP_ANALYSIS;
// Vue.prototype.productBaseUrl = 'http://10.1.5.242:'
// Vue.prototype.productBaseUrl = 'http://10.1.5.243:'
Vue.prototype.productBaseUrl = 'http://1.14.136.44:'
Vue.use(Element, { size: 'small' });
// 同意弹框器
/** 权限指令**/
Vue.directive('has', {
    bind: function (el, binding) {
        if (!Vue.prototype.$_has(binding.value)) {
            if (el.parentNode) {
                el.parentNode.removeChild(el);
            } else {
                el.style.display = 'none';
            }
        }
    }
});
// 消息提示
function message (type, message) {
    this.$message({
        duration: 3000,
        type,
        message
    });
}
// 权限检查方法
Vue.prototype.$_has = function (value) {
    // 处理用户按钮权限
    const buttonPermission =
        JSON.parse(sessionStorage.getItem('buttonPermission')) || [];

    let isExist = false;
    if (!buttonPermission.length) {
        return false;
    }
    if (buttonPermission.includes(+value)) {
        isExist = true;
    }
    return isExist;
};

/** 权限指令**/
Vue.directive('permission', {
    bind: function (el, binding) {
        if (!Vue.prototype.$_permission(binding.value)) {
            if (el.parentNode) {
                el.parentNode.removeChild(el);
            } else {
                el.style.display = 'none';
            }
        }
    }
});
Vue.filter('filteReportType', val => {
    if (val === 'BG_ZT') {
        return '学校总体诊改报告';
    }
    if (val === 'BG_LEVEL_XX') {
        return '层面诊改报告';
    }
    if (val === 'BG_JXDW') {
        return '教学单位诊改报告';
    }
    if (val === 'BG_LEVEL_ZY') {
        return '专业层诊改报告';
    }
    if (val === 'BG_LEVEL_KC') {
        return '课程层诊改报告';
    }
    if (val === 'BG_LEVEL_JS') {
        return '教师层诊改报告';
    }
    return '学生层诊改报告';
});
Vue.filter('filteType', val => {
    if (val === 'XT_WH_XX') {
        return '学校层';
    }
    if (val === 'XT_WH_ZY') {
        return '专业层';
    }
    if (val === 'XT_WH_KC') {
        return '课程层';
    }
    if (val === 'XT_WH_JS') {
        return '教师层';
    }
    if (val === 'XT_WH_XS') {
        return '学生层';
    }
});
Vue.filter('filteStatus', (val, dialogTitle) => {
    if (dialogTitle === '执行进度分析') {
        if (val === 0) {
            return '未完成采集';
        }
        return '已完成采集';
    } else {
        if (val === 0) {
            return '未编辑';
        }
        return '已下发';
    }
});
// 挂载通用common参数
Vue.prototype.common = common;
// 操作消息提示
Vue.prototype.message = message;
// 权限检查方法
Vue.prototype.$_permission = function (value) {
    if (value) {
        // 处理用户按钮权限
        const buttonPermission =
            JSON.parse(sessionStorage.getItem('buttonPermission')) || [];

        let isExist = false;
        if (!buttonPermission.length) {
            return false;
        }

        const arr = [
            'XT_WH_XX',
            'XT_WH_ZY',
            'XT_WH_KC',
            'XT_WH_JS',
            'XT_WH_XS'
        ];
        const currentLevel = value.type;
        let currentLevelName = '';
        switch (currentLevel) {
            case 'BG_LEVEL_XX':
                currentLevelName = 'XT_WH_XX';
                break;
            case 'BG_LEVEL_ZY':
                currentLevelName = 'XT_WH_ZY';
                break;
            case 'BG_LEVEL_KC':
                currentLevelName = 'XT_WH_KC';
                break;
            case 'BG_LEVEL_JS':
                currentLevelName = 'XT_WH_JS';
                break;
            case 'BG_LEVEL_XS':
                currentLevelName = 'XT_WH_XS';
                break;
            default:
                currentLevelName = currentLevel;
        }
        const per = value.per;
        const index = arr.indexOf(currentLevelName);
        if (index > -1) {
            const num = per[index];
            if (buttonPermission.includes(+num)) {
                isExist = true;
            }
        }

        return isExist;
    } else {
        return true;
    }
};

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app');
